/*
author:杨文?
email:yangwenchao@keynection.cn
*/
#pragma once

#ifdef __cplusplus
extern "C" {
#endif
#define MAX_QUEUE_SIZE 10
#include <stdio.h>
#include <stdlib.h>
#include "freertos/FreeRTOS.h"
#include "freertos/semphr.h"
#include "freertos/task.h"

//#include "freertos/semphr.h"
#define MAX_QUEUE_SIZE 10

// 定义任务函数指针类型
typedef void (*task_function)(void *);

// 任务结构体，包含任务函数和参数
typedef struct {
    task_function function;  // 任务函数
    void *arg;               // 参数
} Task;

// 任务队列结构
typedef struct {
    Task queue[MAX_QUEUE_SIZE];  // 队列数组
    int front;   // 队头指针
    int rear;    // 队尾指针
    int size;    // 队列大小
} TaskQueue;
// 定义任务函数指针类型
typedef void (*task_function)(void *);
enum {
    SoftWare_update = 0,
    Reboot,
    FRP,
};

typedef struct  
{
    uint32_t seqNum;
    uint32_t delay;
    uint32_t timestamp;
}reboot_args;
typedef struct
{
    char* frp_ip;
    uint32_t listen_port;
    uint32_t comm_port;
}frp_args;
typedef struct {
    char *type;
    char *firmware_url;
    char *firmware_md5;
    int upgrade_now;
    char *version_current;
} software_update_args_t;

void initQueue(TaskQueue *queue);
int enqueue(TaskQueue *queue, Task task);
Task dequeue(TaskQueue *queue);
void modbus_task_start(void);
void reboot_cmd(void* arg);
void frp(void* arg);
void software_update(void* arg);
void runloop_task(void *param);
void modbus_task_stop(void);
void register_cmd_modbus(void);

extern reboot_args reboot_arg;
extern frp_args frp_arg;
extern software_update_args_t software_update_arg;
extern TaskQueue mb_task_queue;


#ifdef __cplusplus
}
#endif
